﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;

namespace CommonTagTime
{
    public class clsCheck
    {
        public static bool IsEmailAddress(string InputString)
        {
            Regex obj = new Regex(@"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$");
            return obj.IsMatch(InputString);
        }

        public static bool IsVirtualFolderPath(string InputString)
        {
            Regex regex = new Regex(@"^((([.]{2}(\\|/){1}){1,}([a-zA-Z]{1,}(\\|/){1}){0,})|((\\|/){1}([a-zA-Z]{1,}(\\|/){1}){0,})|(([.]{1}|([a-zA-Z]{1,}(\\|/){1}){1,})))$");
            return regex.IsMatch(InputString);
        }

        public static bool QueryString(string QueryString, enmDataType enm)
        {
            string query = HttpContext.Current.Request.QueryString[QueryString];
            if ((query != null) && (query != ""))
            {
                bool b;

                try
                {
                    if (query.Contains("#"))
                    {
                        string[] arr = query.Split('#');
                        switch (enm)
                        {
                            case enmDataType._Int:
                                Convert.ToInt32(arr[0]);
                                break;

                            case enmDataType._DateTime:
                                Convert.ToDateTime(arr[0]);
                                break;

                            case enmDataType._Decimal:
                                Convert.ToDecimal(arr[0]);
                                break;

                            case enmDataType._Boolean:
                                Convert.ToBoolean(arr[0]);
                                break;

                            case enmDataType._String:
                                Convert.ToString(arr[0]);
                                break;
                        }
                    }
                    else
                    {
                        switch (enm)
                        {
                            case enmDataType._Int:
                                Convert.ToInt32(query);
                                break;

                            case enmDataType._DateTime:
                                Convert.ToDateTime(query);
                                break;

                            case enmDataType._Decimal:
                                Convert.ToDecimal(query);
                                break;

                            case enmDataType._Boolean:
                                Convert.ToBoolean(query);
                                break;

                            case enmDataType._String:
                                Convert.ToString(query);
                                break;
                        }
                    }

                    b = true;
                }
                catch
                {
                    b = false;
                }
                return b;
            }
            return false;
        }

    }
}
